<template>
  <div class="app-container">
    <el-form ref="form" :inline="true" :model="queryParams" class="demo-form-inline">
      <el-form-item label="ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="id" />
      </el-form-item>
      <el-form-item label="下注类别" prop="betType">
        <el-select v-model="queryParams.betType" placeholder="请选择">
          <el-option label="余额投注" value="balance" />
          <el-option label="佣金投注" value="kickback" />
        </el-select>
      </el-form-item>
      <el-form-item label="游戏类别" prop="gameType">
        <el-select v-model="queryParams.gameType" placeholder="请选择">
          <el-option label="普通单双" value="0" />
          <el-option label="普通大小" value="1" />
          <el-option label="一分单双" value="2" />
          <el-option label="一分大小" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否保险仓下注" prop="isUseInsuranceBalance">
        <el-select v-model="queryParams.isUseInsuranceBalance" placeholder="请选择">
          <el-option label="否" value="0" />
          <el-option label="是" value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="下注用户ID" align="center" prop="userId" />
      <el-table-column label="下注金额" align="center" prop="betAmount" />
      <el-table-column label="是否保险仓下注" align="center" prop="betAmount">
        <template slot-scope="scope">
          {{ scope.row.isUseInsuranceBalance==0?'否':'是' }}
        </template>
      </el-table-column>
      <el-table-column label="下注" align="center" prop="betCommand" />
      <el-table-column label="下注类别" align="center" prop="betType">
        <template slot-scope="scope">
          <div>
            {{ setBetType(scope.row.betType) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="最终开奖" align="center" prop="checkoutCommand" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="游戏类别" align="center" prop="gameType">
        <template slot-scope="scope">
          <div>
            {{ setGameType(scope.row.gameType) }}
          </div>
        </template>
      </el-table-column>

      <el-table-column label="盈利金额" align="center" prop="winAmount" />

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleAdd(scope.row)">查看</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        :current-page.sync="queryParams.pageNum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="fetchData"
        @current-change="fetchData"
      />
    </div>
    <showInfo ref="showInfo" />
  </div>
</template>

<script>
import { betIndex2 } from '@/api/table'
import showInfo from './showInfo.vue'
export default {
  components: {
    showInfo
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      queryParams: {
        'gameType': '',
        'betType': '',
        'pageNum': 0,
        'pageSize': 10,
        userId: ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      betIndex2(this.queryParams).then(response => {
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    handleShowInfo(e) {
      this.$refs.showInfo.show(e)
    },
    setBetType(id) {
      switch (id) {
        case 'balance':
          return '余额投注'
          break
        case 'kickback':
          return '佣金投注'
          break
        default:
          break
      }
    },
    setGameType(id) {
      switch (Number(id)) {
        case 0:
          return '普通单双'
          break
        case 1:
          return '普通大小'
          break
        case 2:
          return '一分单双'
          break
        case 3:
          return '一分大小'
          break
        default:
          break
      }
    },
    onSubmit() {
      this.queryParams.pageNum = 1
      this.fetchData()
    },
    reset() {
      this.$refs.form.resetFields()

      this.fetchData()
    },
    handleAdd(e) {
      this.$refs.showInfo.show(e)
    },
    handleEdit(e) {
      this.$confirm('此操作将完成订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        transactionEnable(e).then(res => {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '订单成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    handleDel(e) {
      this.$confirm('此操作将取消订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        transactionCancel(e).then(res => {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    }
  }
}
</script>
